//
//  MLAEateryOrderCell.m
//  MagicLampApp
//
//  Created by Zheng on 2019/4/12.
//  Copyright © 2019 zheng.magic.lamp.app. All rights reserved.
//

#import "MLAEateryOrderCell.h"

@implementation MLAEateryOrderCell

- (void)setModel:(MLAEateryOrderModel *)model {
    _model = model;
    
    [_foodImgv sd_setImageWithURL:[NSURL URLWithString:_model.product_imgs]];
    _nameLbl.text = _model.product_name;
    _numLbl.text = [NSString stringWithFormat:@"x%@",_model.num];
    _addressLbl.text = [NSString stringWithFormat:@"地址：%@",_model.address];
    _usernameLbl.text = [NSString stringWithFormat:@"收货人：%@",_model.name];
    _typeLbl.text = [NSString stringWithFormat:@"支付类型：%@",(_model.state.intValue==1? @"线上付款":@"货到付款")];
    _finishLbl.hidden = _model.state.intValue==1? YES: NO;
    _finishBtn.hidden = _model.state.intValue == 1 ? NO: YES;
    
    _priceLbl.text = [NSString stringWithFormat:@"¥ %@",_model.money];
    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    
    [self.contentView sendSubviewToBack:self.shadowView];
    
    _foodImgv.layer.cornerRadius = 5;
    _foodImgv.layer.masksToBounds = YES;
    [_foodImgv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.shadowView).offset(15);
        make.top.equalTo(self.shadowView).offset(20);
        make.height.width.offset(50);
    }];
    
    [_nameLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.foodImgv.mas_right).offset(10);
        make.top.equalTo(self.foodImgv).offset(5);
    }];
    
    [_numLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLbl);
        make.bottom.equalTo(self.foodImgv).offset(-5);
    }];

    [_addressLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.foodImgv.mas_bottom).offset(18);
        make.left.equalTo(self.foodImgv);
    }];
    
    [_usernameLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.addressLbl.mas_bottom).offset(8);
        make.left.equalTo(self.foodImgv);
    }];

    [_typeLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.usernameLbl.mas_bottom).offset(8);
        make.left.equalTo(self.foodImgv);
    }];
    
    [_finishLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.shadowView).offset(-15);
        make.bottom.equalTo(self.shadowView).offset(-18);
    }];
    
    _finishBtn.layer.cornerRadius = 5;
    _finishBtn.layer.masksToBounds = YES;
    _finishBtn.layer.borderWidth = 1;
    _finishBtn.layer.borderColor = CX_GetColorBlue().CGColor;
    [_finishBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.offset(100);
        make.height.offset(30);
        make.bottom.equalTo(self.shadowView).offset(-20);
        make.right.equalTo(self.shadowView).offset(-15);
    }];
}

- (IBAction)btnAction:(id)sender {
    if (_finishAction) {
        _finishAction(_model);
    }
}

@end
